package com.aimei520.controller.converter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;
/**
 * 将输入的字符串转换为日期
 * <p>Title: CustomDateConverter.java</p>  
 * <p>Description: </p>  
 * <p>Copyright: Copyright (c) 2018</p>  
 * <p>Company: www.storyboy.xyz</p>  
 * @author JiaXun  
 * @date 2018年8月29日  
 * @version 1.0.0
 */
public class CustomDateConverter implements Converter<String,Date>{

	@Override
	public Date convert(String source) {
		try {
			
			return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(source);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static void main(String[] args) {
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date_str = df.format(new Date());
		System.out.println(date_str);
		try {
			Date date = df.parse(date_str);
			System.out.println(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

}
